// Fill out your copyright notice in the Description page of Project Settings.

#include "Isalong2.h"
#include "CPlayerCharacterController.h"
#include "CPlayerCharacter.h"
#include "InteractItem.h"
#include "ToolSelectorUI.h"

TArray<FItemUIBlock> UToolSelectorUI::GetToolsData()
{
	TArray<FItemUIBlock> result;
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	TArray<Item> frenData = Character->GetBagDatas();
	for (int i = 0; i < frenData.Num(); i++)
	{
		if (!ItemType::GetIsHoldable(frenData[i]._itemID))
		{
			continue;
		}
		FItemUIBlock fiub;
		fiub._id = frenData[i]._itemID;
		fiub._num = frenData[i]._itemCount;
		fiub._additionValue = frenData[i]._addition;
		fiub._guid = frenData[i]._guid;
		fiub._data = *ItemType::GetItemDisplayByID(fiub._id);
		result.Add(fiub);
	}
	Item temp = Character->GetCurrentHold();
	if (ItemType::GetIsAttachable(temp._itemID))
	{
		FItemUIBlock fiubb;
		fiubb._id = temp._itemID;
		fiubb._num = 1;
		fiubb._additionValue = temp._addition;
		fiubb._guid = temp._guid;
		fiubb._data = *ItemType::GetItemDisplayByID(fiubb._id);
		result.Add(fiubb);
	}
	else
	{
		for (int i=0;i<result.Num();i++)
		{
			if (result[i]._guid==temp._guid)
			{
				result[i]._num += 1;
				break;
			}
		}
	}
	return result;
}

FGuid UToolSelectorUI::GetCurrentHoldWeaponGuid()
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	return Character->GetCurrentHold()._guid;
}

bool UToolSelectorUI::GetIsAttachable(int32 id)
{
	return ItemType::GetIsAttachable(id);
}

int32 UToolSelectorUI::GetCharacterReloadRemain(int32 id)
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	return Character->GetReloadRemainById(id);
}

void UToolSelectorUI::ChangeToolByGuid(FGuid guid)
{
	ACPlayerCharacter* Character = Cast<ACPlayerCharacter>(ACPlayerCharacterController::_localPlayerController->GetPawn());
	Character->ChangeWeaponByGuid(guid);
}
